package controller;
import java.io.IOException;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import dao.WeiGuiDao;
import model.WeiGui;

/**
 * Servlet implementation class UpdateUserServlet
 */
@WebServlet("/UpdateWeiGuiServlet")
public class UpdateWeiGuiServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	
	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		request.setCharacterEncoding("UTF-8");
		 	String id = request.getParameter("id");
	        String time = request.getParameter("time");
	        String type = request.getParameter("type");
	        String because = request.getParameter("because");
	        String address = request.getParameter("address");
	        //以上为更新提交后的信息,以下为旧信息
	        String oldid = request.getParameter("oldid");
	        String oldtime = request.getParameter("oldtime");
	        String oldtype = request.getParameter("oldtype");
	        
	        
	        WeiGui wg = new WeiGui(id, time, type, because,address);
	        WeiGuiDao dao = new WeiGuiDao();
	        
	        
	        boolean success = dao.updateMsg(wg,oldid,oldtime,oldtype);
	        
	        if (success) {
	            response.sendRedirect("View_WeiGui/WeiGuiSG.jsp"); // 更新成功后跳转到用户列表页面
	        } else {
	            response.getWriter().write("UPDATEFAILE");
	        }
	}

}